#include <stdio.h>
#include <pthread.h>
#include <sched.h>
#include <unistd.h>

unsigned long global_a = 0;
unsigned long global_b = 0;

void *thread_routine(void *arg)
{
    int cpu = 100000000;
    while (1)
    {
        (*((unsigned long *)arg))++;
    }
};
void test_cpu_switch()
{
    pthread_t thread_a;
    pthread_create(&thread_a, NULL, thread_routine, &global_a);
    pthread_detach(thread_a);

    pthread_t thread_b;
    pthread_create(&thread_b, NULL, thread_routine, &global_b);
    pthread_detach(thread_b);

    usleep(3000000); //3000毫秒
    printf("thread-a:%lu\tthread-b:%lu\n", global_a, global_b);
}

int main()
{

    while (1)
    {
        test_cpu_switch();
    }
    return 0;
}